package main

import (
	"bytes"
	"io"
	"os"
)

func main()  {
	var w io.Writer
	w = os.Stdout			// ok: *os.File has write method
	w = new(bytes.Buffer)   // ok: *bytes.Buffer has write method
	//w = time.Second		// compile error: time.Duration lacks Write method

	var rwc io.ReadWriteCloser
	rwc = os.Stdout			// ok: *os.File has Read, Write, Close methods
	//rwc = new(bytes.Buffer)  // compile error: *bytes.Buffer lacks Close method

	w = rwc
	w.Write([]byte("abc"))	// ok: io.ReadWriteCloser has Write method
	//rwc = w 				// compile error: io.Writer lacks Close method


	os.Stdout.Write([]byte("hello"))  // ok: *os.File has Write method
	os.Stdout.Close()				  // ok: *os.File has Close method

	var w2 io.Writer
	w2 = os.Stdout
	_, _ = w2.Write([]byte("hello")) // ok: io.Writer has Write method
	// w.Close()  // compile error: io.Writer lacks Close method



}

type IntSet struct {}

func (*IntSet) String() string  {
	return "abc"
}

// var _ = IntSet{}.String()  // compile error: String require *IntSet receiver

var s IntSet
var _ = s.String()  // 编译器隐式获取了变量的地址













